import moment from "moment";
import { ref, computed } from 'vue'
export function useDateRange(cb: any) {
    const startTimeVal = ref(
        moment(new Date()).startOf("day").format("YYYY-MM-DD HH:mm:ss")
    );
    const endTimeVal = ref(
        moment(new Date()).endOf("day").format("YYYY-MM-DD HH:mm:ss")
    );
    const show = ref(false);

    const onConfirm = (values: any) => {
        const [start, end] = values;
        show.value = false;

        startTimeVal.value = moment(start)
            .startOf("day")
            .format("YYYY-MM-DD HH:mm:ss");
        endTimeVal.value = moment(end).endOf("day").format("YYYY-MM-DD HH:mm:ss");
        cb && cb();
    };
    const date = computed(() => {
        return `${moment(startTimeVal.value).format('MM-DD')}至${moment(endTimeVal.value).format('MM-DD')}`;
    });
    return {
        show,
        startTimeVal,
        endTimeVal,
        onConfirm,
        date
    };
}
